package com.xuanyuan.material

import android.os.Bundle
import android.text.Editable
import android.text.TextWatcher
import com.xuanyuan.base.BaseActivity
import com.xuanyuan.material.databinding.ActivityTextInputLayoutBinding


/**
 * TextInputLayout&TextInputEditText
 * 两个各自的不同
 */
class TextInputLayoutActivity : BaseActivity<ActivityTextInputLayoutBinding>() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        val editText=mBinding.tilName.editText

        editText?.addTextChangedListener(object : TextWatcher {
            override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) {
                // 文本变化前调用
            }

            override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) {
                // 文本发生变化时调用
            }

            override fun afterTextChanged(s: Editable) {
                // 文本发生变化后调用
                if (editText.text.toString().trim().length > 8) {
                    mBinding.tilName.error = "用户名长度超过8位"
                } else {
                    mBinding.tilName.error = null
                }
            }
        })


    }

    override fun initLayout(): Int {
     return   R.layout.activity_text_input_layout
    }

    override fun afterInit() {

    }
}